package oracle_sql_option

import (
	"database/sql"
	"log"
	"strconv"
	"time"
)

type Ora_stu struct {
	EMPNO    int
	ENAME    string
	JOB      string
	MGR      sql.NullInt64
	HIREDATE time.Time
	SAL      sql.NullInt64
	COMM     sql.NullInt64
	DEPTNO   sql.NullInt64
	C营业收入元   sql.NullString `sql:"营业收入元"`
}

func Oracle_Option_CY(sql string, db *sql.DB) error {
	tm := time.Now()
	row, err := db.Query(sql)
	if err != nil {
		return err
	}
	num := 1
	for row.Next() {
		var nda Ora_CY
		if err = row.Scan(&nda.C流水号,
			&nda.C确认级别,
			&nda.C单位类别,
			&nda.C组织机构代码,
			&nda.C详细名称,
			&nda.C单位负责人,
			&nda.C行政区划代码,
			&nda.C详细地址,
			&nda.C长途区号,
			&nda.C固定电话,
			&nda.C固话分机号,
			&nda.C移动电话,
			&nda.C传真号码,
			&nda.C传真分机号,
			&nda.C邮政编码,
			&nda.C电子邮箱,
			&nda.C主要业务活动1,
			&nda.C主要业务活动2,
			&nda.C主要业务活动3,
			&nda.C行业代码,
			&nda.C机关级别_工商,
			&nda.C机关级别_编制,
			&nda.C机关级别_民政,
			&nda.C机关级别_国税,
			&nda.C机关级别_地税,
			&nda.C机关级别_其他,
			&nda.C登记注册号_工商,
			&nda.C登记注册号_编制,
			&nda.C登记注册号_民政,
			&nda.C登记注册号_国税,
			&nda.C登记注册号_地税,
			&nda.C登记注册号_其他,
			&nda.C登记注册类型,
			&nda.C开业年份,
			&nda.C开业月份,
			&nda.C企业营业状态,
			&nda.C机构类型,
			&nda.C期末从业人数,
			&nda.C经营性单位收入,
			&nda.C非经营性单位支出,
			&nda.C零售业态,
			&nda.C归属法人组织机构代码,
			&nda.C归属法人详细名称,
			&nda.C归属法人详细地址,
			&nda.C归属法人行政区划代码,
			&nda.C建筑业年报,
			&nda.C批零贸易业年报,
			&nda.C批零贸易业定报,
			&nda.C住宿餐饮业年报,
			&nda.C住宿餐饮业定报,
			&nda.C企业景气调查年报,
			&nda.C企业景气调查定报,
			&nda.C劳动统计,
			&nda.C报表选项,
			&nda.C统计负责人,
			&nda.C实际负责人,
			&nda.C填表人,
			&nda.C填表日期,
			&nda.C统计局代码,
			&nda.C入库日期,
			&nda.C最后修改日期,
			&nda.C状态,
			&nda.C专业标识,
			&nda.C附加选项1,
			&nda.C附加选项2,
			&nda.C附加选项3,
			&nda.C附加选项4,
			&nda.C附加选项5,
			&nda.C附加选项6,
			&nda.C附加标记1,
			&nda.C附加标记2,
			&nda.C附加标记3,
			&nda.C附加标记4,
			&nda.C附加标记5,
			&nda.C附加标记6,
			&nda.C普查,
			&nda.C变更类别,
			&nda.C确认专业,
			&nda.C旧代码,
			&nda.C主要业务活动1_11,
			&nda.C行业代码_11,
			&nda.C网址,
			&nda.C批零经营形式,
			&nda.C批零营业面积,
			&nda.C住餐经营形式,
			&nda.C住宿业星级,
			&nda.C住餐营业面积,
			&nda.C填表人移动电话,
			&nda.C行政区划代码_旧,
			&nda.C剔除原因,
			&nda.C剔除原因描述,
			&nda.C归属法人行政区划代码_旧,
			&nda.C经普唯一标识码,
			&nda.C建筑物编码,
			&nda.C经营战略性新兴产业产品,
			&nda.C战略性新兴产业产品收入,
			&nda.C文化产业单位,
			&nda.C健康服务业单位,
			&nda.C养老服务业单位,
			&nda.C不诚信单位,
			&nda.C版本,
			&nda.C社会信用代码,
			&nda.C归属法人社会信用代码,
			&nda.C经营形式,
			&nda.CG公司类型,
			&nda.CG注册时间,
			&nda.CG经营范围,
			&nda.CG财务,
			&nda.CG财务固话,
			&nda.CG财务手机,
			&nda.CG法人固话,
			&nda.CG法人手机,
			&nda.CG异常名录,
			&nda.CG违法失信,
			&nda.CG注销日期,
			&nda.CG经营期限自,
			&nda.CG经营期限止,
			&nda.C工业园区代码_45,
			&nda.C众创_45,
			&nda.C众包_45,
			&nda.C众扶_45,
			&nda.C众筹_45,
			&nda.C经度_45,
			&nda.C纬度_45,
			&nda.C附加标记7_45,
			&nda.C附加标记8_45,
			&nda.C附加标记9_45,
			&nda.C连锁品牌,
			&nda.C零售业态2,
			&nda.C零售业态3); err != nil {
			return err
		}
		if num%1000 == 0 {
			log.Println("已用时间==：", time.Since(tm), "||过滤数据：", num)
		}
		// log.Println("||过滤数据：", num)
		num++
	}
	if err := row.Err(); err != nil {
		return err
	}
	log.Println("总耗时==：", time.Since(tm))
	return nil
}

func Oracle_Option(sql string, db *sql.DB) error {
	tm := time.Now()
	row, err := db.Query(sql)
	if err != nil {
		return err
	}
	num := 1
	for row.Next() {
		var nda Ora_stu
		if err = row.Scan(&nda.EMPNO, &nda.ENAME, &nda.JOB, &nda.MGR, &nda.HIREDATE, &nda.SAL, &nda.COMM, &nda.DEPTNO, &nda.C营业收入元); err != nil {
			return err
		}
		if num%1000 == 0 {
			log.Println("已用时间==：", time.Since(tm), "||过滤数据：", num)
		}
		num++
	}
	if err := row.Err(); err != nil {
		return err
	}
	log.Println("总耗时==：", time.Since(tm))
	return nil
}

func leveltest(dbName string) {
	tm := time.Now()
	db, err := OpenLevelDb(dbName)
	if err != nil {
		log.Println("open levelDB have err", err)
		return
	}
	var data []LevelData
	for i := 0; i < 100000; i++ {
		var ts LevelData
		ts.LevelKey = []byte(strconv.Itoa(i))
		ts.LevelValue = []byte(strconv.Itoa(i))

		data = append(data, ts)
	}
	BatchDataInput(db, data)
	defer db.Close() //关闭数据库
	log.Println("time ==:", time.Since(tm))
}
